#!/usr/bin/env python
#coding:utf-8

from commands import getoutput
#引入上层目录模块方法
import sys
sys.path.append("..")

from core.level import InfoData,WarningData


def get_memory_info(args):
    '''监控内存使用率'''
    result = getoutput('''free -m|grep buffers/cache|awk '{print $(NF-1)","$NF}' ''')
    used, free = result.split(',')
    if int(used) >= args.get('WarningData'):
        return WarningData({'内存使用': [int(used), 'MB'],'内存剩余':[int(free), 'MB']})
    return InfoData({'内存使用': [int(used), 'MB'],'内存剩余':[int(free), 'MB']})
   
#if __name__ == '__main__':
    #print get_memory_info('')
